home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / STRCHR.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  943b  |  64 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strchr- Returns the position of a single character in a string.
  10. ;
  11. ; inputs:
  12. ;
  13. ;    al- character to search for.
  14. ;    es:di- address of string.
  15. ;
  16. ; returns: 
  17. ;
  18. ;    cx- position of character in string (if present).
  19. ;    carry=0 if character found.
  20. ;    carry=1 if character is not present in string.
  21. ;
  22.         public    sl_strchr
  23. ;
  24. sl_strchr    proc    far
  25.         pushf
  26.         push    ds
  27.         push    si
  28.         push    ax
  29.         cld
  30. ;
  31.         mov    si, es        ;Setup ds:si to use LODSB
  32.         mov    ds, si
  33.         mov    si, di
  34. ;
  35.         mov    ah, al        ;ah=char to search for.
  36. strchrlp:    lodsb
  37.         cmp    al, ah
  38.         jz    FndChr
  39.         cmp    al, 0
  40.         jne    strchrlp
  41. ;
  42.         xor    cx, cx
  43.         pop    ax
  44.         pop    si
  45.         pop    ds
  46.         popf
  47.         stc
  48.         ret
  49. ;
  50. FndChr:        pop    ax
  51.         mov    cx, si
  52.         sub    cx, di
  53.         dec    cx
  54.         pop    si
  55.         pop    ds
  56.         popf
  57.         clc
  58.         ret
  59. sl_strchr    endp
  60. ;
  61. ;
  62. stdlib        ends
  63.         end
  64.